package com.yiligi.myserver.controller;

import com.yiligi.myserver.common.ResStatus;
import com.yiligi.myserver.common.ResultVO;
import com.yiligi.myserver.pojo.Student;
import com.yiligi.myserver.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/student/select")
    public ResultVO getStudentList(@RequestParam int pageNum,
                                   @RequestParam int pageSize,
                                   @RequestParam String studentId,
                                   @RequestParam String name,
                                   @RequestParam String studentClass){
        int total = studentService.selectTotal(studentId,name,studentClass);
        List<Student> students = studentService.selectStudentPage(pageNum,pageSize,studentId,name,studentClass);
        Map<String,Object> res = new HashMap<>();
        res.put("total",total);
        res.put("data",students);
        return new ResultVO(ResStatus.OK,"查询成功",res);
    }

}
